<template>
	<view class="tab-container bg-white">
		<view class="cu-list menu">
			<view class="cu-item arrow" v-if="accounts.length > 0" v-for="(item, key) in accounts" :key="key"
				:data-item="item" @click="myAccountDetail(item)">
				<view class="content padding-tb-sm">
					<view>
						<text class="cuIcon-rechargefill text-green margin-right-xs"></text> {{item.acctTypeName}}
					</view>
					<view class="text-gray text-sm">
						<text class="cuIcon-right margin-right-xs"></text>余额: {{item.amount}}
					</view>
				</view>
				<view class="action">
				</view>
			</view>
			<view class="cu-item arrow" @click="coupons(item)">
				<view class="content padding-tb-sm">
					<view>
						<text class="cuIcon-ticket text-green margin-right-xs"></text>我的优惠券
					</view>
					<view class="text-gray text-sm">
					</view>
				</view>
				<view class="action">

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant;
	import {
		queryOwnerAccount
	} from '../../api/user/userApi.js'

	export default {
		data() {
			return {
				accounts: []
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			this.loadOwnerAccount()
		},
		created() {
			// 获取积分
			this.loadOwnerAccount()
			
		},
		methods: {
			coupons: function(_item) {
				uni.navigateTo({
					url: '/pages/myAccount/myCoupons',
				})
			},
			myAccountDetail: function(_item) {
				uni.navigateTo({
					url: '/pages/myAccount/myAccountDetail?acctId=' + _item.acctId
				});
			},
			/**
			 * 加载优惠券信息
			 */
			loadOwnerAccount: function() {
				let _that = this;
				let userPhone = uni.getStorageSync("commonUser");
				_that.phone = userPhone.phone
				uni.request({
					url: constant.url.getCoupons,
					header: context.getHeaders(),
					method: "GET",
					data: {
						phone:_that.phone,
					},
					success: function(res) {
						_that.accounts = res.data.result;
						console.log("优惠券",_that.accounts)
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				})
			}
		}
	};
</script>
<style>
	@import "./myAccount.css";
</style>
